<?php
include_once("survey_question_dao_base.php");

class survey_question_dao extends survey_question_dao_base
{
	function get_survey_question_list_by_survey_id($survey_id)
	{
		try
		{
			$dbh = new PDO(Constants::$connectionString, Constants::$username, Constants::$password);
			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			$dbh->beginTransaction();

			$aos = array();
			$stmt = $dbh->query("SELECT * FROM survey_question sq WHERE sq.survey_id = ".$survey_id);
			$rows = $stmt->fetchAll();
			foreach($rows as $row)
			{
				$s = new survey_question($row["survey_question_id"],$row["survey_id"],$row["survey_question_content"],$row["customer_id"]);
				$aos[] = $s;
			}

			$dbh->commit();
			$dbh = null;
			
			return $aos;
		}
		catch(PDOException $e)
		{
			echo '<br />' . $e->getMessage();
			$dbh->rollback();
		}	
	}
	
	function delete_survey_question_by_survey_id($survey_id)
	{
		try
		{
			$dbh = new PDO(Constants::$connectionString, Constants::$username, Constants::$password);
			$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			$dbh->beginTransaction();

			$stmt = $dbh->prepare("DELETE FROM survey_question WHERE survey_id = :survey_id");
			$stmt->bindParam(':survey_id', $survey_id, PDO::PARAM_INT);
			$stmt->execute();
			
			$dbh->commit();
			$dbh = null;
		}
		catch(PDOException $e)
		{
			echo '<br />' . $e->getMessage();
			$dbh->rollback();
		}	
	}

}
?>